import time

from tools.base_page import BasePage


class CreateQueue(BasePage):

    def create_queue_action(self,name_text,assess_text):
        '''
        申请创建队列 必填项
        :param name_text:提交成功后团队名称
        :param assess_text: 预期团队名称
        :return:
        '''

        self.open_yaml_element('../data/index.yaml','duilie_name',content=name_text)
        self.open_yaml_element('../data/index.yaml','fuzeren')
        ele = self.only_read_yaml('../data/index.yaml', 'option_num')[1]
        self.selector_execute_script(ele)
        #self.driver.execute_script('document.querySelector("body>div:nth-of-type(5)>div>div>div>ul>li:nth-of-type(6)").click()')
        ele_list = ['xiayibu','kaoshi_assess']
        for ele in ele_list:
            self.open_yaml_element('../data/index.yaml',ele)
            time.sleep(1)
        self.open_yaml_element('../data/index.yaml','assess_text_view',content=assess_text)
        self.open_yaml_element('../data/index.yaml','apply_for')
        team_name_locator = self.only_read_yaml('../data/index.yaml','team_name')

        name_text = self.find(team_name_locator).text
        return name_text


    def not_must(self):
        '''
        基本信息非必填项
        :return:
        '''

        time.sleep(2)
        hexin_member_locator = self.only_read_yaml('../data/index.yaml', 'hexin_member')[1]
        option_num_nine = self.only_read_yaml('../data/index.yaml','option_num_six')[1]
        time.sleep(3)
        locator_list = [hexin_member_locator,option_num_nine]
        for ele in locator_list:
            self.selector_execute_script(ele)
            time.sleep(1)
        self.open_yaml_element('../data/index.yaml','linshi_meber')
        time.sleep(2)
        self.open_yaml_element('../data/index.yaml','linshi_meber_input')
        time.sleep(2)
        option_ten_locator = self.only_read_yaml('../data/index.yaml','option_six')[1]
        self.selector_execute_script(option_ten_locator)
        self.open_yaml_element('../data/index.yaml','linshi_meber')
        time.sleep(2)
        self.open_yaml_element('../data/index.yaml','xiayibu')
        return self



    def construction_target(self,yanjiu_text,target_text):
        '''
        建设目标
        :param yanjiu_text:研究背景文本值
        :param target_text:队列建设目标文本值
        :return:
        '''
        self.elementclickintercepted(self.only_read_yaml('../data/index.yaml','jianshe_target'))
        self.open_yaml_element('../data/index.yaml','yanjiu_beijing',content=yanjiu_text)
        self.open_yaml_element('../data/index.yaml','duilie_jianshe_target',content=target_text)
        self.open_yaml_element('../data/index.yaml','apply_for')
        return self



    def yanjiu_content(self,text_value1,text_value2,text_value3):
        '''
        text_value1:技术路线内容
        text_value2 解决关键问题输入内容
        text_value3 创新点输入内容
        :return:
        '''

        yanjiuneirong_locator = self.only_read_yaml('../data/index.yaml', 'yanjiuneirong')
        self.elementclickintercepted(yanjiuneirong_locator)
        self.open_yaml_element('../data/index.yaml', 'yanjiuluxian',content=text_value1)
        self.open_yaml_element('../data/index.yaml', 'jiejue_questions',content=text_value2)
        self.open_yaml_element('../data/index.yaml', 'chuangxindian',content=text_value3)
        return self


    def kaohe_target(self,kaohe_text_value):
        '''
        考核指标
        :return:
        '''
        time.sleep(2)
        locator = self.only_read_yaml('../data/index.yaml', 'kaohe_zhibiao')
        js = self.find(locator)
        self.driver.execute_script("arguments[0].click();", js)

        time.sleep(2)
        self.open_yaml_element('../data/index.yaml', 'zhibiao_input',content=kaohe_text_value)
        self.open_yaml_element('../data/index.yaml', 'apply_for')
        time.sleep(3)
        return self


    def examine_submit_whether_succeed(self):
        '''
        所有必填项不填写，非必填项全部填写时提交。检查提交是否成功
        :return:
        '''
        submit_hint = self.only_read_yaml('../data/index.yaml','submit_hint')   # 提示语
        submit_text = self.find(submit_hint).text
        return submit_text


    def must_and_not_must(self,name_text):
        # 必填项和非必填项填写
        self.open_yaml_element('../data/index.yaml','duilie_name',content=name_text)
        self.open_yaml_element('../data/index.yaml','fuzeren')
        ele = self.only_read_yaml('../data/index.yaml', 'option_num')
        self.verify_wait_click(self.only_read_yaml('../data/index.yaml', 'option_num'))
        self.selector_execute_script(ele[1])
        #self.driver.execute_script('document.querySelector("body>div:nth-of-type(5)>div>div>div>ul>li:nth-of-type(6)").click()')

    def get_team_name(self):
        team_name_locator = self.only_read_yaml('../data/index.yaml','team_name')
        name_text = self.find(team_name_locator).text
        return name_text